<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>测试classList</title>
    <style>
      div {
        width: 100px;
        height: 100px;
        background-color: pink;
      }
      .test {
          background-color: red;
      }
      .pig {
          width: 200px;
      }
    </style>
  </head>
  <body>
    <div></div>
    <button class="pig">按钮</button>
    <script>
        let btn = document.getElementsByTagName('button')[0]
        btn.addEventListener('click',function(){
            this.classList.add('pig')
            this.classList.toggle('test')
        })
    </script>
  </body>
</html>
